package reflect;

import java.lang.reflect.Method;
import java.lang.reflect.Modifier;

public class Test {
    public static void main(String[] args) throws Exception {
        Class cla = Class.forName("reflect.Person");
        Object obj = cla.newInstance();

        Method[] methods = cla.getDeclaredMethods();
        for (Method method:methods) {
            //System.out.println(method.getName());
            //int a = method.getParameterCount();
            //method.setAccessible(true);
            if (method.getParameterCount()==0 && method.getModifiers()== Modifier.PUBLIC
            && method.getName().contains("e")) {
                System.out.println("调用方法"+method.getName()+"()");
                //method.setAccessible(true);
                method.invoke(obj);
            }
        }
    }
}

